#include "Controller.h"
#include <Windows.h>

Controller::Controller()
{
	isRunning = true;
}
Controller::~Controller(){}

void Controller::Run()
{
	Ser.Init(this);
	while(isRunning)
	{
		Ser.RunCommCheck(&Cmd);
	}
}

bool Controller::Send()
{
	int processGameNum = Cmd.getGameNumber();
	newGame = Cmd.getCmdType();
	bool access[4] = {true,true,true,true};
	
	//check if a new game needs to be created
	if(newGame == SSpawn)
	{
		for(int Count = 0; Count <= NUM_MAX_CLIENTS; Count++)
		{
			if(access[Count])
			{
				//create new game
				p_game[processGameNum] = new GameState;
				fakegame[processGameNum] = new FakeGameState;
				//access = true;
				//p_game[processGameNum]->Send(&Cmd);

			}
			//else {newGame == SQuit;}
		}
	}
	if(newGame == SQuit)
	{
		//end current game
		delete(p_game[processGameNum]);
		//PostQuitMessage(0);
	}
	return fakegame[processGameNum]->Send(&Cmd);
	return p_game[processGameNum]->Send(&Cmd);
	
	//check if a new game needs to be created
	//for(processGameNum; processGameNum < NUM_MAX_CLIENTS; processGameNum++)
	//{
	//	if(newGame == SSpawn)
	//	{
	//		//create new game
	//		p_game[processGameNum] = new GameState;
	//		fakegame[processGameNum] = new FakeGameState;
	//	}
	//	if(newGame == SQuit)
	//	{
	//		//end current game
	//		//delete(p_game[processGameNum]);
	//		//PostQuitMessage(0);
	//	}
	////}
	//return fakegame[processGameNum]->Send(&Cmd);
	//return p_game[processGameNum]->Send(&Cmd);
	//return true;
}